package sweetsaremeat.beehive.View;

import sweetsaremeat.beehive.Model.Vector2;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.FloatMath;

public class Hexagon 
{
	/** Constants */
	private final float c_xFactor = (float)Math.cos(30.0 * Math.PI / 180);
    private final float c_yFactor = (float)Math.sin(30.0 * Math.PI / 180);
    
    //the original side length of a hexagon (before it's been scaled)
    public static final float c_size = 40;
	
    /** Variables */
    public Vector2 m_center; //start point is the upper-left corner of the surrounded rectangle
	
    //hexagon points
    public Vector2 m_p1; //upper-left
    public Vector2 m_p2; //top
    public Vector2 m_p3; //upper-right
    public Vector2 m_p4; //lower-right
    public Vector2 m_p5; //bottom
    public Vector2 m_p6; //lower-left
	
    public Path m_path;
	
    
    public Hexagon()
    {
    	m_center = new Vector2();
    	
    	m_p1 = new Vector2();
    	m_p2 = new Vector2();
    	m_p3 = new Vector2();
    	m_p4 = new Vector2();
    	m_p5 = new Vector2();
    	m_p6 = new Vector2();
    	
    	m_path = new Path();
    }
    
    
	// computes the 6 points of a hexagon
    public void SetHexagonPoints(float a_centerX, float a_centerY, float a_sideLength)
    {
    	//set the center pos
    	m_center.x = a_centerX;
    	m_center.y = a_centerY;
    	
    	// first point: left-upper
        m_p1.x = a_centerX - a_sideLength * c_xFactor;
        m_p1.y = a_centerY - a_sideLength * c_yFactor; 
        
        // 2nd point: top
        m_p2.x = a_centerX;
        m_p2.y = a_centerY - a_sideLength;

        // 3rd point: right-upper
        m_p3.x = a_centerX + a_sideLength * c_xFactor;
        m_p3.y = m_p1.y;

        // 4th point: right-lower
        m_p4.x = m_p3.x;
        m_p4.y = m_p3.y + a_sideLength;

        // 5th point: bottom
        m_p5.x = m_p2.x;
        m_p5.y = m_p4.y + a_sideLength * c_yFactor;

        // 6th point: left-lower
        m_p6.x = m_p1.x;
        m_p6.y = m_p4.y;
    }
    
    public Path CalcPath()
    {
    	//reset the path
    	m_path.reset();
    	
    	// first point: left-upper
        m_path.moveTo(m_p1.x, m_p1.y);
        
        // 2nd point: top
        m_path.lineTo(m_p2.x, m_p2.y);

        // 3rd point: right-upper
        m_path.lineTo(m_p3.x, m_p3.y);

        // 4th point: right-lower
        m_path.lineTo(m_p4.x, m_p4.y);

        // 5th point: bottom
        m_path.lineTo(m_p5.x, m_p5.y);

        // 6th point: left-lower
        m_path.lineTo(m_p6.x, m_p6.y);
        
        m_path.lineTo(m_p1.x, m_p1.y); // first=last point 
        
        
        return m_path;
    }
}
